package com.ncp.servlet.product;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ncp.model.biz.comment.CommentCl;
import com.ncp.model.biz.comment.CommentScoCl;
import com.ncp.model.entity.comment.ProductComment;
import com.ncp.model.entity.product.CommentBean;

public class CommentScoServlet extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		int ProductID=Integer.parseInt(request.getParameter("ProductID"));
		int nowPage=1;
		 int showPages=4;

		 String p=request.getParameter("page");
		 if(p!=null&&!p.equals("")){
		 	nowPage=Integer.parseInt(p);
		 }
		 
		 CommentCl cc=new CommentCl();
		 int PageCount=cc.getCount(ProductID);
		 int Numbers = cc.getCommentNum(ProductID); 
		 CommentScoCl csc=new CommentScoCl();
		 float star=csc.formatFloat(csc.getAvgSco(ProductID));
		 ArrayList<ProductComment> list=cc.getCommentInfo(ProductID,nowPage);
		 
		 CommentBean cb = new CommentBean();
		 cb.setCommentNumber(Numbers);
		 cb.setPagecount(PageCount);
		 cb.setStar(star);
		 request.setAttribute("list", list);
		 request.setAttribute("cb", cb);
		 request.setAttribute("nowPage", nowPage+"");
		 request.getRequestDispatcher("pages/comment/page.jsp").forward(request,response);

	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		this.doGet(request, response);

	}

}
